#!/bin/sh

war=zyj-web-war

/data/tomcat-7.0.82-yj-core/bin/stop.sh
cd /data/tomcat-7.0.82-yj-core/webapps/ && rm -rf ROOT
mv ~/"$war"*.war /data/tomcat-7.0.82-yj-core/webapps/"$war".war
unzip /data/tomcat-7.0.82-yj-core/webapps/"$war".war -d /data/tomcat-7.0.82-yj-core/webapps/ROOT
cd /data/tomcat-7.0.82-yj-core/webapps/ &&  rm -rf "$war".war
rm -rf ~/"$war"*.war


env=$1

#写入本机名称与IP到hosts
#HOST_IP=$(ifconfig eth0 |grep 'inet addr' |awk {'print $2'} | sed 's/addr://')
#HOST_NAME=$(hostname)
#HOSTS=$HOST_IP' '$HOST_NAME
#HOSTS_EXSITS=$(grep "$HOSTS" /etc/hosts)

#if [ "$HOSTS" != "$HOSTS_EXSITS" ]; then
#    echo $HOSTS >> /etc/hosts
#fi

if [ $env = "pro" ]; then
    cp -R /data/tomcat-7.0.82-yj-core/webapps/ROOT/WEB-INF/classes/pro-springme.xml /data/tomcat-7.0.82-yj-core/webapps/ROOT/WEB-INF/classes/springme.xml
    cp -R /data/tomcat-7.0.82-yj-core/webapps/ROOT/WEB-INF/classes/pro-logback.xml /data/tomcat-7.0.82-yj-core/webapps/ROOT/WEB-INF/classes/logback.xml
elif [ $env = "test" ]; then
    cp -R /data/tomcat-7.0.82-yj-core/webapps/ROOT/WEB-INF/classes/test-springme.xml /data/tomcat-7.0.82-yj-core/webapps/ROOT/WEB-INF/classes/springme.xml
else
    echo "不支持的环境类型，目前支持只【pro/test】"
    exit 1
fi

#启动tomcat
/data/tomcat-7.0.82-yj-core/bin/startup.sh